#include "fifo_exeattr.h"
#include <string.h>
#include "stdlib.h"
#include "cn_tcpserver.h"
#include "task.h"
#include  "cn_usart_x.h"
#include "cn_cmd_exeattr.h"
//处理wifi收到的数据,转换发给对应的串口或者指令配置,长度不包括CRC和尾，若需要增增加3
uint8_t wlan_recv_process(uint8_t *sdata, uint32_t len)
{
	MsgResult_t result = NO_CMD;
	struct comdata *p_msg = (struct comdata*)sdata; 
	uint32_t lenth = len;
	wm_printf("wlan_recv_process \n");
	switch (p_msg->type)
	{
		case 0x01://代表是配置类型
			wm_printf("Msg_Feedback \n");
			result =  Msg_Execute((u8 *)p_msg,len);
			if (result != NO_ACK) //如果执行结果不为 不回应
			{
				Msg_Feedback(p_msg); //执行回应信息上报，
			}
			break;

		case 0x02://代表是透传类型，也就是数据转发给串口
			wm_printf("cn_uart_write \n");
			cn_uart_write(p_msg->cmd,  &sdata[10] ,lenth - 10);
			break;

		default:
			break;
	}	
	return TRUE;
}
extern int send_tcpclient(uint8_t *data,uint32_t len);
extern int send_udp(uint8_t *data,uint32_t len);
//处理收到的数据，长度不包括CRC和尾，若需要增增加3
uint8_t wlan_send_process(uint8_t *sdata, uint32_t len)
{
	wm_printf("wlan_send_process \n");
	switch (sdata[3])
	{
		case 1:
			send_udp(sdata,len + 3);
			break;
		
		case 2:
			send_tcpclient(sdata,len + 3);
			break;
			
		default:
			break;
	}
	return TRUE;
}

void Msg_Feedback(struct comdata *p_msg)
{
	struct comdata *Smsg = (struct comdata *)p_msg;	
	cmd_put(&rcv_usart_fifo, (u8 *)Smsg, (Smsg->length + 6)); 
}